import socket
import struct

def send_router_solicitation(interface):
    # 创建IPv6 UDP套接字
    sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)

    # 准备IPv6路由器请求
    ipv6_header = b'\x60\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00'
    router_solicitation = b'\x01\x01\x00\x00' + b'\x00' * 12

    # 组装IPv6报文
    packet = ipv6_header + router_solicitation

    # 发送路由器请求
    sock.sendto(packet, ('ff02::2', 0, 0, interface))

    print("发送路由器请求")

if __name__ == "__main__":
    try:
        # 获取用户输入的网络接口名称
        interface = input("请输入网络接口名称：")

        # 发送路由器请求
        send_router_solicitation(interface)
    except Exception as e:
        print("\033[1;31;40m[*]发生错误:", e)
        print("\033[1;37;40m")
